//
//  MBPhotoItemView.m
//  Meboo
//
//  Created by kyo on 2024/3/12.
//

#import "MBPhotoItemView.h"

@interface MBPhotoItemView()

@end
@implementation MBPhotoItemView

#pragma mark - Life Cycle
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public Metohd

#pragma mark - Action
- (void)deleteAction {
    self.photoImageView.image = ImageWithName(@"profile_photo_back");
    if (self.deletePhotoBlock) {
        self.deletePhotoBlock();
    }
}

#pragma mark - UI
- (void)setupUI {
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.photoImageView];
    [self.photoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    [self addSubview:self.deleteBtn];
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.mas_equalTo(MBHeightScale(0));
        make.width.height.mas_equalTo(MBHeightScale(24));
    }];
    
    [self addSubview:self.coverBtn];
    [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(MBWidthScale(49));
        make.height.mas_equalTo(MBHeightScale(18));
        make.bottom.mas_equalTo(MBHeightScale(-8));
        make.centerX.equalTo(self);
    }];
}

#pragma mark - Setter && Getter
- (UIImageView *)photoImageView {
    if (!_photoImageView) {
        _photoImageView = [UIImageView new];
        _photoImageView.contentMode = UIViewContentModeScaleAspectFill;
        _photoImageView.layer.cornerRadius = MBHeightScale(12);
        _photoImageView.layer.masksToBounds = YES;
    }
    return _photoImageView;
}

- (UIButton *)deleteBtn {
    if (!_deleteBtn) {
        _deleteBtn = [[UIButton alloc] init];
        _deleteBtn.hidden = YES;
        [_deleteBtn setImage:ImageWithName(@"register_photo_delete") forState:0];
        [_deleteBtn setYXEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
        [_deleteBtn addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteBtn;
}

- (UIButton *)coverBtn {
    if (!_coverBtn) {
        _coverBtn = [[UIButton alloc] init];
        _coverBtn.enabled = NO;
        [_coverBtn setBackgroundColor:[UIColor colorWithRed:185 / 255.0 green:84 / 255.0 blue:255 / 255.0 alpha:0.5]];
        [_coverBtn setTitle:@"Cover" forState:0];
        _coverBtn.titleLabel.font = MBFontSizeScale(12);
        _coverBtn.layer.cornerRadius = MBHeightScale(6);
    }
    return _coverBtn;
}

@end

